package com.ys.web.pay.model.po;

import com.ys.base.EnumType;
import com.ys.utils.base.http.McodeHandler;
import com.ys.utils.base.j2se.Convert;
import com.ys.utils.base.j2se.StringHandler;
import com.ys.utils.spring.config.SystemError;
import com.ys.utils.spring.properties.Config;
import lombok.Data;

/**
 * 转账
 */
@Data
public class TransferCreate extends WalletBase{

    public void check(){
        if(StringHandler.parseMoney(this.getAmount())==0){
            SystemError.wrapBs("400","参数异常");
        }
        if(this.getGp().equals("1")){
            this.setReceivedId(StringHandler.getString(McodeHandler.from32Radix(this.getReceivedId())));
        }

        long compareMoney = StringHandler.getLong(StringHandler.parseMoney(this.getAmount()));
        long min = StringHandler.getLong(Config.pp.get("wallet.transfer.money.min"));
        if (compareMoney < min) {
            SystemError.wrapBs("400", "转账金额不能小于" + StringHandler.moneyDesc(min) + "元");
        }
        long max = StringHandler.getLong(Config.pp.get("wallet.transfer.money.max"));
        if (compareMoney > max) {
            SystemError.wrapBs("400", "转账金额不能大于" + StringHandler.moneyDesc(max) + "元");
        }
        if(this.payChannel<1){
            SystemError.wrapBs("400","请选择钱包类型....");
        }
        this.setAmount(String.valueOf(StringHandler.yuanToFen(this.getAmount())));

        this.setReceivedIds(StringHandler.getString(McodeHandler.from32Radix(this.getReceivedIds())));

        this.setType(EnumType.MessageCode.MESSAGE_TRANSFER.getCode());
    }
}
